import { EmployeeLoginComponent } from './../employeeLogin/employeeLogin.component';
import { SearchLDCComponent } from './../searchLDC/searchLDC.component';
import { NavController } from 'ionic-angular';
import { NavigateService } from './../../service/navigate.service';
import { Component, OnInit, HostListener } from '@angular/core';

@Component({
    //moduleId: module.id,
    selector: "div[init]",
    templateUrl: "./init.component.html"
})
export class InitComponent implements OnInit {
    constructor(
        private router: NavigateService,
        public navCtrl: NavController
    ) { }
    title: string = "初始化设置";

    // @HostListener('document:keyup', ['$event'])
    // onKeyUp(ev: KeyboardEvent) {
    //     if (ev.keyCode == 13) {
    //         this.next();
    //     }
    // }

    ngOnInit() {
        this.checkEnv();
    }

    next() {
        // this.router.navigate(['searchLDC', 'auto']);
        this.navCtrl.setRoot(SearchLDCComponent, {
            searchMode: 'auto'
        })
    }
    /**
     * 如果已经店长登录并配置了LDC，跳转到店员登录
     */
    private checkEnv() {
        let LDCAddress = localStorage.getItem("LDCAddress");
        let storeOwner = localStorage.getItem("StoreOwner");
        let store = localStorage.getItem("store");
        let terminal = localStorage.getItem("terminal");
        if (LDCAddress && storeOwner && store && terminal) {
            // this.router.navigate(['employeeLogin']);
            this.navCtrl.setRoot(EmployeeLoginComponent);
        }
    }
}